package com.uam.utils.file.analysis.help;

import com.uam.common.exception.UamException;
import com.uam.utils.StringUtils;
import lombok.Getter;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 文件类型枚举
 *
 * @author heguanglong
 * @date 2020-12-02
 */
public enum GeoTypeEnums {

    /**
     * 点
     */
    POINT(1, "POINT"),

    /**
     * 线
     */
    LING(2, "LINESTRING"),


    /**
     * 面
     */
    Polygon(3, "POLYGON"),
    /**
     * 复合点
     */
    MULTIPOINT(1, "MULTIPOINT"),

    /**
     * 复合线
     */
    MULTILINESTRING(2, "MULTILINESTRING"),


    /**
     * 面
     */
    MULTIPOLYGON(3, "MULTIPOLYGON");



    @Getter
    private Integer code;
    @Getter
    private String name;


    GeoTypeEnums(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    private static Map<String, Integer> file2GeoJsonMap = new ConcurrentHashMap<>();

    static {
        for (GeoTypeEnums typeEnums : values()) {
            file2GeoJsonMap.put(typeEnums.getName(), typeEnums.getCode());
        }
    }

    public static Integer getCode(String type) {
        String key=type.toUpperCase();
        Integer geoJson = file2GeoJsonMap.get(key);
        if (geoJson == null) {
            throw UamException.paramError("点线面不存在 type：" + type);
        }
        return geoJson;
    }
}
